<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "collect".
 *
 * @property int $id
 * @property int $uid
 * @property int $pid
 * @property string $remarks
 * @property string $created_at
 */
class Collect extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'collect';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['uid', 'pid'], 'integer'],
            [['remarks','created_at'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'uid' => 'Uid',
            'pid' => 'Pid',
            'remarks' => 'Remarks',
            'created_at' => '收藏时间',
        ];
    }

	public function beforeSave($insert)
	{
		if (static::findOne(['uid'=>$this->uid,'pid'=>$this->pid])!= null){
			return false;
		}
		if(parent::beforeSave($insert)){
			if ($insert){
				$this->created_at = time();
			}
			return true;

		}else{
			return false;
		}
	} 
}
